﻿
namespace Aeon.Emulator.Instructions
{
    internal static class Conversions
    {
        [Opcode("98", Name = "cbw", AddressSize = 16 | 32)]
        public static void ByteToWord(VirtualMachine vm)
        {
            vm.Processor.AX = (sbyte)vm.Processor.AL;

            vm.Processor.InstructionEpilog();
        }
        [Alternate("ByteToWord", AddressSize = 16 | 32)]
        public static void ByteToWord32(VirtualMachine vm)
        {
            vm.Processor.EAX = vm.Processor.AX;

            vm.Processor.InstructionEpilog();
        }

        [Opcode("99", Name = "cwd", AddressSize = 16 | 32)]
        public static void WordToDword(VirtualMachine vm)
        {
            int result = vm.Processor.AX;
            vm.Processor.DX = (short)((result >> 16) & 0xFFFF);

            vm.Processor.InstructionEpilog();
        }
        [Alternate("WordToDword", AddressSize = 16 | 32)]
        public static void WordToDword32(VirtualMachine vm)
        {
            long result = (long)vm.Processor.EAX;
            vm.Processor.EDX = (int)((result >> 32) & 0xFFFFFFFF);

            vm.Processor.InstructionEpilog();
        }
    }
}
